package com.huatai.datacenter.controller.datasubject;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.datacenter.entity.subject.SubjectBarGraphVO;
import com.huatai.dataservice.entity.SubjectDataSetEntity;
import com.huatai.datacenter.entity.subject.SubjectNodeVO;
import com.huatai.datacenter.entity.subject.SubjectTaskVO;
import com.huatai.datacenter.service.SubjectDataSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gusiyi
 * @version 1.0
 * @className SubjectDataSetController
 * @description 描述：
 * @date 2023/6/7 14:09
 */
@RestController
@Api(value = "主题数据集管理",tags = "主题数据集管理")
@RequestMapping("/dataSubject/dataSet")
public class SubjectDataSetController {

	@Autowired
	private SubjectDataSetService subjectDataSetService;

	@RequestMapping("/getSubjectNode")
	@ApiOperation("获取主题数据集菜单节点")
	@ApiOperationSupport(order = 1)
	public R<SubjectNodeVO> getSubjectTree(@RequestBody Map<String, Integer> typeContent) {
		Integer typeContent1 = typeContent.get("typeContent");
		return R.data(subjectDataSetService.getSubjectTree(typeContent1),"获取主题数据集菜单节点成功");
	}

	@RequestMapping("/addDataSet")
	@ApiOperation("在主题目录下添加数据集")
	@ApiOperationSupport(order = 2,includeParameters = {
		"dataSetEntity.subjectDirectoryId",
		"dataSetEntity.subjectDirectoryName",
		"dataSetEntity.subjectDataSetName",
		"dataSetEntity.remark",
		"dataSetEntity.dataAccessTaskTypeNum",
		"dataSetEntity.dataAccessTaskTypeName",
		"dataSetEntity.dataAccessTaskName",
		"dataSetEntity.dataAccessTaskTable"
	})
	public R<SubjectDataSetEntity> addDataSet(@RequestBody SubjectDataSetEntity dataSetEntity){
		return R.status(subjectDataSetService.save(dataSetEntity));
	}

	@RequestMapping("/deleteDataSet")
	@ApiOperation("删除数据集")
	@ApiOperationSupport(order = 4,includeParameters = {
		"subjectDataSetEntity.id"
	})
	public R<SubjectDataSetEntity> deleteDataSet(@RequestBody SubjectDataSetEntity subjectDataSetEntity){
		subjectDataSetEntity.setDeleted(true);
		return R.status(subjectDataSetService.updateById(subjectDataSetEntity));
	}

	@RequestMapping("/getDataSetInfo")
	@ApiOperation("获取数据集信息")
	@ApiOperationSupport(order = 5,includeParameters = {
		"subjectDataSetEntity.id",
		"subjectDataSetEntity.pageIndex",
		"subjectDataSetEntity.pageSize"
	})
	public R<Page<LinkedHashMap<String,Object>>> getDataSetInfo(@RequestBody SubjectDataSetEntity subjectDataSetEntity){
		return R.data(subjectDataSetService.getDataSetInfo(subjectDataSetEntity));
	}

	@RequestMapping("/getDataAccessTask")
	@ApiOperation("获取接入任务二级菜单")
	@ApiOperationSupport(order = 3,includeParameters = {
		"dataSetEntity.dataAccessTaskTypeNum"
	})
	public R<List<SubjectTaskVO>> getDataAccessTask(@RequestBody SubjectDataSetEntity dataSetEntity){
		return R.data(subjectDataSetService.getDataAccessTask(dataSetEntity));
	}

	@RequestMapping("/getDataSetBarGraph")
	@ApiOperation("获取主题数据集柱状图")
	@ApiOperationSupport(order = 6,includeParameters = {
		"index"
	})
	public R<SubjectBarGraphVO> getDataSetBarGraph(@RequestParam("index") Integer index){
		return 	R.data(subjectDataSetService.getDataSetBarGraphVO(index));
	}

	@RequestMapping("/addDataSetToRedis")
	@ApiOperation("更新主题数据集")
	@ApiOperationSupport(order = 7)
	public R<SubjectBarGraphVO> addDataSetToRedis(){
		subjectDataSetService.addDataSetCountBarGraph();
		return R.success("更新成功");
	}

}
